package com.spn.blog.api.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.spn.blog.api.vo.ResultMessage;
import org.apache.tomcat.jni.Time;
import org.joda.time.DateTime;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class MessageUtils {
    public static String getMessage(boolean isSystemMsg,
                                    String fromName, Object msg){
        ResultMessage resultMessage = new ResultMessage();
        resultMessage.setTime(new Date());
        resultMessage.setIsSystem(isSystemMsg);
        resultMessage.setMessage(msg);
        if (fromName != null) {
            resultMessage.setFromName(fromName);
        }
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.writeValueAsString(resultMessage);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
